from unittest import TestCase
from ddt  import ddt,data,unpack
from selenium import webdriver
from Bank_cardOperation import Bank_cardOperation
from Bank_card_data import Bank_card_data

@ddt
class Test3Bank_card(TestCase):
#########################################################################################
###################################     新增银行卡      ###################################
    @data(*Bank_card_data.Bank_card_add_data)
    @unpack
    def testBank_card1(self,username,password,cardname,cardtype,cardnum,expect,case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        bc = Bank_cardOperation()
        num1 = bc.bank_card_before(driver,username,password)
        bc.bank_card_add(driver,cardname,cardtype,cardnum)
        num2 = bc.bank_card_after(driver)
        result = bc.getResult1(num1,num2)

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect,result)

#########################################################################################
###################################     删除卡测试      ###################################

    @data(*Bank_card_data.Bank_card_del_data)
    @unpack
    def testBank_card2(self, username, password,expect, case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        bc = Bank_cardOperation()
        num1 = bc.bank_card_before(driver, username, password)
        bc.bank_card_del(driver,num1,expect)
        num2 = bc.bank_card_after(driver)
        result = bc.getResult1(num1, num2)

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect, result)

#########################################################################################
###################################     编辑银行卡      ###################################

    @data(*Bank_card_data.Bank_card_edit_data)
    @unpack
    def testBank_card3(self, username, password, cardname, cardtype , cardnum ,expect, case):

        #  开始测试
        driver = webdriver.Chrome()

        driver.get("http://localhost:90")
        driver.maximize_window()

        bc = Bank_cardOperation()
        num1 = bc.bank_card_before(driver, username, password)
        num = bc.bank_card_edit(driver,cardname,cardtype,cardnum,num1)
        result = bc.getResult2(num[0], num[1])

        if result != expect:
            driver.save_screenshot(f'D:/Users/北极星的眼泪/Desktop/demo/自动化测试第三四天/报错截图/{case}.png')
        else:
            print("通过")

        driver.quit()

        self.assertEqual(expect, result)